package com.example.springblog.model;

import com.example.springblog.constants.Constant;
import lombok.Data;


/*
* 统一返回结果的实体类
* */
@Data
public class Result {
    private int code;
    private String msg;
    private Object data;
    //1，业务执行成功返回的方法
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_SUCCESS);
        result.setMsg("");
        result.setData(data);
        return result;
    }

    //2,业务执行失败返回的方法
    public static Result fail(int code, String msg){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_FAIL);
        result.setData("");
        result.setMsg(msg);
        return result;
    }

    //3，用户未登录返回的方法
    public static Result unlogin(int code,String msg,Object data){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_UNLOGIN);
        result.setData(data);
        result.setMsg("用户未登录");
        return result;
    }

    public static Result unlogin(Object data){
        Result result = new Result();
        result.setCode(Constant.RESULT_CODE_UNLOGIN);
        result.setData(data);
        result.setMsg("用户未登录");
        return result;
    }
}
